﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace StockTrader.FrontEnd.DataContract
{
    public class OrderUI : IComparer
    {
        private string _accountNo;
        public string AccountNo
        {
            get { return _accountNo; }
            set { _accountNo = value; }
        }
        private string _accountNoChange;
        public string AccountNoChange
        {
            get { return _accountNoChange; }
            set { _accountNoChange = value; }
        }
        private string _orderSide;
        public string Side
        {
            get { return _orderSide; }
            set { _orderSide = value; }
        }
        private string _symbol;
        public string Symbol
        {
            get { return _symbol; }
            set { _symbol = value; }
        }
        private string _price;
        public string Price
        {
            get { return _price; }
            set { _price = value; }
        }
        private string _priceChange;
        public string PriceChange
        {
            get { return _priceChange; }
            set { _priceChange = value; }
        }
        private long _volume;
        public long Volume
        {
            get { return _volume; }
            set { _volume = value; }
        }
        private string _orderStatus;
        public string Status
        {
            get { return _orderStatus; }
            set { _orderStatus = value; }
        }
        private long _volumeMatched;
        public long MVolume
        {
            get { return _volumeMatched; }
            set { _volumeMatched = value; }
        }
        public decimal _averagePrice;
        public decimal AveragePrice
        {
            get { return _averagePrice; }
            set { _averagePrice = value; }
        }
        private decimal _valueMatched;
        public decimal MValue
        {
            get { return _valueMatched; }
            set { _valueMatched = value; }
        }
        private string _orderTimestamp;
        public string Time
        {
            get { return _orderTimestamp; }
            set { _orderTimestamp = value; }
        }
        private string _orderNumber;
        public string OrderNo
        {
            get { return _orderNumber; }
            set { _orderNumber = value; }
        }
        private string _market;
        public string Market
        {
            get { return _market; }
            set { _market = value; }
        }
        private List<HoseOrderChangeUI> _changeDetail;
        public List<HoseOrderChangeUI> ChangeDetail
        {
            get { return _changeDetail; }
            set { _changeDetail = value; }
        }
        private List<OrderMatchedUI> _matchedDetail;
        public List<OrderMatchedUI> MatchedDetail
        {
            get { return _matchedDetail; }
            set { _matchedDetail = value; }
        }
        private OrderCancelUI _cancelDetail;
        public OrderCancelUI CancelDetail
        {
            get { return _cancelDetail; }
            set { _cancelDetail = value; }
        }
        private DateTime _transDate;
        public System.DateTime TransDate
        {
            get { return _transDate; }
            set { _transDate = value; }
        }


        public OrderUI()
        {

        }
        public OrderUI(string ts, string ordernum, string accountno, string accChange, string side, string symbol, long vol, string price, string status, string priceChange, long mvol, decimal averagePrice, decimal mvalue, List<HoseOrderChangeUI> change, List<OrderMatchedUI> match, OrderCancelUI cancel, string market)
        {
            this._orderTimestamp = ts;
            this._orderNumber = ordernum;
            this._accountNo = accountno;
            this._accountNoChange = accChange;
            this._orderSide = side;
            this._symbol = symbol;
            this._volume = vol;
            this._price = price;
            this._priceChange = priceChange;
            this._volumeMatched = mvol;
            this._averagePrice = averagePrice;
            this._valueMatched = mvalue;
            this._matchedDetail = match;
            this._changeDetail = change;
            this._cancelDetail = cancel;
            this._market = market;
            this._orderStatus = status;
        }

        public OrderUI(DateTime transdate, string ts, string ordernum, string accountno, string accChange, string side, string symbol, long vol, string price, string status, string priceChange, long mvol, decimal averagePrice, decimal mvalue, List<HoseOrderChangeUI> change, List<OrderMatchedUI> match, OrderCancelUI cancel, string market)
        {
            this._transDate = transdate;
            this._orderTimestamp = ts;
            this._orderNumber = ordernum;
            this._accountNo = accountno;
            this._accountNoChange = accChange;
            this._orderSide = side;
            this._symbol = symbol;
            this._volume = vol;
            this._price = price;
            this._priceChange = priceChange;
            this._volumeMatched = mvol;
            this._averagePrice = averagePrice;
            this._valueMatched = mvalue;
            this._matchedDetail = match;
            this._changeDetail = change;
            this._cancelDetail = cancel;
            this._market = market;
            this._orderStatus = status;
        }

        #region IComparer Members

        public int Compare(object x, object y)
        {
            OrderUI order1;
            OrderUI order2;
            order1 = x as OrderUI;
            order2 = y as OrderUI;

            if (order1 == null)
                if (order2 == null)
                    return 0;
                else
                    return -1;
            else
                if (order2 == null)
                    return 1;
                else
                    return order1.Time.CompareTo(order2.Time);
        }

        #endregion
    }

    public class OrderMatchedUI
    {
        private string _timeStamp;
        public string TimeStamp
        {
            get { return _timeStamp; }
            set { _timeStamp = value; }
        }
        private string _orderNumber;
        public string OrderNumber
        {
            get { return _orderNumber; }
            set { _orderNumber = value; }
        }
        private long _volumeMatched;
        public long Volume
        {
            get { return _volumeMatched; }
            set { _volumeMatched = value; }
        }
        private decimal _priceMatched;
        public decimal Price
        {
            get { return _priceMatched; }
            set { _priceMatched = value; }
        }
        private string _valueMatched;
        public string ValueMatched
        {
            get { return _valueMatched; }
            set { _valueMatched = value; }
        }
        private string _confirmNumber;
        public string ConfirmNumber
        {
            get { return _confirmNumber; }
            set { _confirmNumber = value; }
        }


        private string _counterAccountNo;
        public string MAccount
        {
            get { return _counterAccountNo; }
            set { _counterAccountNo = value; }
        }


        public OrderMatchedUI()
        {
        }
        public OrderMatchedUI(string ts, string ordernum, string confirmnum, long mvol, decimal mprice, string counteracc)
        {
            this._timeStamp = ts;
            this._orderNumber = ordernum;
            this._confirmNumber = confirmnum;
            this._volumeMatched = mvol;
            this._priceMatched = mprice;
            this._valueMatched = (mvol * mprice * 1000).ToString("N0");
            this._counterAccountNo = counteracc;
        }
    }
    public class OrderCancelUI
    {
        private string mTimestamp;
        public string Timestamp
        {
            get { return mTimestamp; }
            set { mTimestamp = value; }
        }

        private string mOrderNumber;
        public string OrderNumber
        {
            get { return mOrderNumber; }
            set { mOrderNumber = value; }
        }

        private long mCancelShares;
        public long CancelShares
        {
            get { return mCancelShares; }
            set { mCancelShares = value; }
        }

        private string mOrderCancelStatus;
        public string OrderCancelStatus
        {
            get { return mOrderCancelStatus; }
            set { mOrderCancelStatus = value; }
        }

        public OrderCancelUI() { }
        public OrderCancelUI(string timestamp, string ordernum, long cancelshares, string status)
        {
            this.mTimestamp = timestamp;
            this.mOrderNumber = ordernum;
            this.mCancelShares = cancelshares;
            this.mOrderCancelStatus = status;
        }
    }
    public class HoseOrderChangeUI
    {
        private string mTimestamp;
        public string Timestamp
        {
            get { return mTimestamp; }
            set { mTimestamp = value; }
        }

        private string mOrderNumber;
        public string OrderNumber
        {
            get { return mOrderNumber; }
            set { mOrderNumber = value; }
        }

        private string mClientID;
        public string ClientID
        {
            get { return mClientID; }
            set { mClientID = value; }
        }

        private string mPortClientFlag;
        public string PortClientFlag
        {
            get { return mPortClientFlag; }
            set { mPortClientFlag = value; }
        }

        private long mPublishedVolume;
        public long PublishedVolume
        {
            get { return mPublishedVolume; }
            set { mPublishedVolume = value; }
        }

        private string mPrice;
        public string Price
        {
            get { return mPrice; }
            set { mPrice = value; }
        }        

        public HoseOrderChangeUI() { }
        public HoseOrderChangeUI(string ts, string ordernum, string clientid, string port, long mvol, string price)
        {
            this.mTimestamp = ts;
            this.mOrderNumber = ordernum;
            this.mClientID = clientid;
            this.mPortClientFlag = port;
            this.mPublishedVolume = mvol;
            this.mPrice = price;
        }

    }

    public class OrderImported
    {
        private string _accountNo;
        public string AccountNo
        {
            get { return _accountNo; }
            set { _accountNo = value; }
        }
        private string _orderSide;
        public string Side
        {
            get { return _orderSide; }
            set { _orderSide = value; }
        }
        private string _symbol;
        public string Symbol
        {
            get { return _symbol; }
            set { _symbol = value; }
        }
        private string _price;
        public string Price
        {
            get { return _price; }
            set { _price = value; }
        }
        private long _volume;
        public long Volume
        {
            get { return _volume; }
            set { _volume = value; }
        }
        private long _volumeMatched;
        public long MVolume
        {
            get { return _volumeMatched; }
            set { _volumeMatched = value; }
        }
        private string _orderTimestamp;
        public string Time
        {
            get { return _orderTimestamp; }
            set { _orderTimestamp = value; }
        }


        public OrderImported()
        {

        }
        public OrderImported(string ts, string accountno, string side, string symbol, long vol, string price, long mvol)
        {
            this._orderTimestamp = ts;
            this._accountNo = accountno;
            this._orderSide = side;
            this._symbol = symbol;
            this._volume = vol;
            this._price = price;
            this._volumeMatched = mvol;
        }
    }
}
